package cn.swust.designpatternlearningplatform.common.utils;


import cn.swust.designpatternlearningplatform.domain.bo.TokenInfoBo;

/**
 * description: 授权用户的上下文对象
 * 将解析出来的token信息放入此对象中，在该请求的任何地方均可调用
 */
public class AuthUserContext {

    private final static ThreadLocal<TokenInfoBo> TOKEN_INFO_BO_THREAD_LOCAL = new ThreadLocal<>();

    public static TokenInfoBo get() {
        return TOKEN_INFO_BO_THREAD_LOCAL.get();
    }

    public static void set(TokenInfoBo tokenInfoBo) {
        TOKEN_INFO_BO_THREAD_LOCAL.set(tokenInfoBo);
    }

    /**
     * 不要忘了clear，防止内存泄漏
     */
    public static void clear() {
        if (TOKEN_INFO_BO_THREAD_LOCAL.get() != null) {
            TOKEN_INFO_BO_THREAD_LOCAL.remove();
        }
    }

}
